for _ in range(int(input())):
n = int(input())
a = [int(i) for i in input().split()]
l, r = None, None
for i in range(n-1):
if a[i] == a[i+1] :
if l == None : l = i
r = i
if l == r : print(0)
else : print(max(1, r-l-1))
/******************************************************/
/******************************************************/
/** BISMILLAHIR RAHMANIR RAHIM **/
/** Md.Faysal Ahamed - ER3N YAGER **/
/** Department of Computer Science and Engineering **/
/** Barisal University **/
/** It's time to Roar. **/
/******************************************************/
/******************************************************/
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll N=1e9+7;
void solv()
{
ll n; cin>>n;
ll arr[n];
for(ll i=0; i<n; i++)cin>>arr[i];
ll mx=-1,mn=-1;
// ll First,Last;
for(ll i=0; i<n-1; i++)
{
if(arr[i]==arr[i+1])
{
if(mn==-1)mn=i+1;
mx=i+1;
}
}
if(mn==mx)cout<<0<<endl;
else cout<<max(mx-mn-1,1*1ll)<<endl;
}
int main()
{
optimize();
ll t; cin>>t;
while(t--)
{
solv();
}
}
/***************** ALHAMDULILLAH *****************/
1025D - Recovering BST | 439A - Devu the Singer and Churu the Joker |
1323A - Even Subset Sum Problem | 1095A - Repeating Cipher |
630F - Selection of Personnel | 630K - Indivisibility |
20B - Equation | 600B - Queries about less or equal elements |
1015A - Points in Segments | 1593B - Make it Divisible by 25 |
680C - Bear and Prime 100 | 1300A - Non-zero |
1475E - Advertising Agency | 1345B - Card Constructions |
1077B - Disturbed People | 653A - Bear and Three Balls |
794A - Bank Robbery | 157A - Game Outcome |
3B - Lorry | 1392A - Omkar and Password |
489A - SwapSort | 932A - Palindromic Supersequence |
433A - Kitahara Haruki's Gift | 672A - Summer Camp |
1277A - Happy Birthday Polycarp | 577A - Multiplication Table |
817C - Really Big Numbers | 1355A - Sequence with Digits |
977B - Two-gram | 993A - Two Squares |